package com.holyn.mylibrary;

import android.app.Dialog;
import android.content.Context;
import android.graphics.PorterDuff;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.ContentLoadingProgressBar;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

/**
 * Created by Holyn on 2017/6/6.
 */

public class LoadingDialog {
    private Context context;
    private Dialog mDialog;
    private View mDialogContentView;
    private ContentLoadingProgressBar contentLoadingProgressBar;
    private TextView tvContent;

    public LoadingDialog(Context context) {
        this.context = context;
        init();
    }

    private void init(){
        mDialog = new Dialog(context, R.style.tran_dialog);
        mDialogContentView = LayoutInflater.from(context).inflate(R.layout.dialog_loading, null);
        contentLoadingProgressBar = (ContentLoadingProgressBar)mDialogContentView.findViewById(R.id.content_loading_bar);
        contentLoadingProgressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(context,R.color.color_loading), PorterDuff.Mode.MULTIPLY);
        tvContent = (TextView)mDialogContentView.findViewById(R.id.tv_loading_text);
        setCanceledOnTouchOutside(false);
        mDialog.setContentView(mDialogContentView);
    }

    public void show(){
        mDialog.show();
    }

    public void dismiss(){
        mDialog.dismiss();
    }

    public void setCanceledOnTouchOutside(boolean cancel){
        mDialog.setCanceledOnTouchOutside(cancel);
    }

    public boolean isShowing(){
        return mDialog.isShowing();
    }

    public void setContent(String content){
        tvContent.setText(content);
    }
}
